﻿// =================================================================
//  Copyright (c) "David R. Guindo", Software architect
//  
//  This code is released under the terms of the Apache License, Version 2.0,
//  http://www.apache.org/licenses/LICENSE-2.0
//  
//  THIS CODE AND INFORMATION ARE PROVIDED WITHOUT WARRANTIES,
//  WITHOUT LIMITING COMMERCIAL OR PARTICULAR USE.
// =================================================================

namespace ScreenManager.Configuration
{
   using System.Configuration;

   public class WindowCollection : ConfigurationElementCollection
   {
      public override ConfigurationElementCollectionType CollectionType
      {
         get
         {
            return ConfigurationElementCollectionType.AddRemoveClearMap;
         }
      }

      public SMWindow this[int index]
      {
         get
         {
            return (SMWindow)this.BaseGet(index);
         }
         set
         {
            if (this.BaseGet(index) != null)
            {
               this.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
         }
      }

      public void Add(SMWindow element)
      {
         this.BaseAdd(element);
      }

      public void Clear()
      {
         this.BaseClear();
      }

      public void Remove(SMWindow element)
      {
         this.BaseRemove(element.Name);
      }

      public void Remove(string name)
      {
         this.BaseRemove(name);
      }

      public void RemoveAt(int index)
      {
         this.BaseRemoveAt(index);
      }

      protected override ConfigurationElement CreateNewElement()
      {
         return new SMWindow();
      }

      protected override object GetElementKey(ConfigurationElement element)
      {
         return ((SMWindow)element).Name;
      }
   }
}